/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rploo_ciayoo.kontrol;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import oracle.jdbc.pool.OracleDataSource;
//import oracle.jdbc.pool.OracleDataSource;


public class KoneksiDatabase {

//     String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//    String userid = "hr";
//    String password = "qwerty";
    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "MHS105314010";
    String password = "MHS105314010";
    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;

    public Connection getDBConnection() {
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();

            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);

            System.out.println("Koneksi berhasil");
        } catch (SQLException ex) {
            System.out.println("Masih belum konek");
        }
        return conn;
    }
// ini method yang digunakan apabila kita melakkukan close.
//    Maka secara otomatis koneksi  tidak akan tertutup.

    public void close() {
        try {
            conn.close();
        } catch (SQLException ex) {
            System.out.println("Tidak bisa tutup koneksi");
        }
    }

    public static void main(String[] args) throws SQLException {
        KoneksiDatabase datahandler = new KoneksiDatabase();
        datahandler.getDBConnection();
        datahandler.close();
    }
}
